package com.zr.bookcorner;

import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import com.lurencun.service.autoupdate.AppUpdate;
import com.lurencun.service.autoupdate.AppUpdateService;
import com.zh.baselibrary.base.ScreenAdapter;
import com.zh.baselibrary.constant.BaseConstant;
import com.zh.baselibrary.netutils.HRetrofitNetHelper;
import com.zh.baselibrary.utils.CrashHandler;
import com.zh.baselibrary.utils.LogUtils;
import com.zh.baselibrary.utils.ShareManager;
import com.zh.baselibrary.views.ToastView;
import com.zr.andealib.util.constant.AndeaConstant;

import org.xutils.x;

import java.io.File;

/**
 * @author EnzoChan
 * @create 2019/4/8
 * @desc:
 */
public class BookApplication extends Application {
    AppUpdate appUpdate;
    private static int myScreenWidth;
    private static int myScreenHeight;
    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        HRetrofitNetHelper.isJdb = false;
        x.Ext.init(this);
        ToastView.init(this);
        appUpdate = AppUpdateService.getAppUpdate(this);
        appUpdate.callOnResume();

        BaseConstant.canSpeak = ShareManager.getInt(context, BaseConstant.DEVICE_VOICE)==1;
         CrashHandler.getInstance().init(this);

    }

    private void initScreenWidth() {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager)
                this.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(metrics);
        myScreenWidth = metrics.widthPixels;
        myScreenHeight = metrics.heightPixels;
        LogUtils.e("width:" + myScreenWidth);
    }
    //享阅柜开机后分辨率会变化、旋转
    public static void  retSet(){
        ScreenAdapter.setup((Application) context);
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(metrics);
        myScreenWidth = metrics.widthPixels;
        myScreenHeight = metrics.heightPixels;
        LogUtils.e("width:" + myScreenWidth);
        ScreenAdapter.register((Application) context, isBig() ? 1280 : 800, ScreenAdapter.MATCH_BASE_WIDTH, ScreenAdapter.MATCH_UNIT_DP);
        if (isNormal())
            AndeaConstant.CARD_TTY = "/dev/ttyUSB0";
        else
            AndeaConstant.CARD_TTY = "/dev/ttyS3";

        if (isBig())
            AndeaConstant.LOCK_TTY = "/dev/ttyS0";
        else
            AndeaConstant.LOCK_TTY = "/dev/ttyS2";
    }

    public static Context getContext() {
        return context;
    }

    public static boolean isBig() {
        return myScreenWidth == 1280;
    }

    public static boolean isMini() {
        return myScreenWidth == 600;
    }

    public static boolean isNormal() {
        return myScreenWidth == 800;
    }


}
